﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 渐变.user_Form
{
    public partial class user_Recharge : Form
    {
        public user_Recharge()
        {
            InitializeComponent();
        }
        public string opname { get; set; }
        private void user_Recharge_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
        }

        private void btnSub_Click(object sender, EventArgs e)
        {
            //比对数据库中的账号与密码
            string sql = "select * from Recharge";
            DataTable dt = new DataTable();
            dt = DBHelper.ExecuteQuery(sql);
            string account = dt.Rows[0][1].ToString();
            string password = dt.Rows[0][2].ToString();
            if(txtAccount.Text==account)
            {
                if(txtPassword.Text == password)
                {
                    //成功后更新该用户的余额
                    string sql2 = "update uUser set umoney=umoney+@rechargeMoney where uUsername=@uUsername";
                    SqlParameter[] ps =
                    {
                    new SqlParameter("@rechargeMoney",Convert.ToDecimal(txtMoney.Text)),
                    new SqlParameter("@uUsername",this.opname)
                };
                    int res = DBHelper.ExecuteNonQuery(sql2, ps);
                    if (res > 0)
                    {
                        this.ShowSuccessTip("充值成功！");
                    }
                    else
                    {
                        this.ShowErrorTip("充值失败！");
                    }
                }
                else
                {
                    this.ShowErrorTip("密码错误！");
                }
               

            }
            else
            {
                //错误
                this.ShowErrorTip("卡号不存在！");
            }


        }
    }
}
